﻿Imports System.Threading


Partial Class TrangChu
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        Page.Title = WebConfigServer.GetValueWebConfigByKey("web_des")
        If Not IsPostBack Then
            ''Check device
            Dim bIsMobileDevice As Boolean = False
            Dim mobileDeviceDoc As XDocument = XDocument.Load(Server.MapPath("~/MobileDevices.xml"))
            Dim mobileDevices = From devices In mobileDeviceDoc.Root.Elements()
            For Each device As XElement In mobileDevices
                If Not String.IsNullOrEmpty(device.Value) Then
                    If (Request.UserAgent.IndexOf(device.Value, StringComparison.OrdinalIgnoreCase)) > 0 Then
                        bIsMobileDevice = True
                        Exit For
                    End If
                End If
            Next
            'end:foreach loop
            bIsMobileDevice = True
            If Not bIsMobileDevice Then
                Response.Redirect("http://www.khachsan24gio.vn")
                Exit Sub
            End If
            '    Response.Redirect("index.aspx")
            'Else          
            'End check
            Dim _Date As Date = DateAdd(DateInterval.Day, +1, Now.Date)
            divNhanPhong.InnerHtml = String.Format("<div class='day-month'><div class='day'>{0}</div><div class='month'>T{1}</div></div><div class='date'>{2}</div>", Util.GetThuTrongTuan(CInt(Now.DayOfWeek)), Now.Month, Now.Day)
            divTraPhong.InnerHtml = String.Format("<div class='day-month'><div class='day'>{0}</div><div class='month'>T{1}</div></div><div class='date'>{2}</div>", Util.GetThuTrongTuan(CInt(_Date.DayOfWeek)), _Date.Month, _Date.Day)
            ArrivalDate.Value = Now.Year.ToString() + "/" + Now.Month.ToString() + "/" + Now.Day.ToString()
            DepartureDate.Value = _Date.Year.ToString() + "/" + _Date.Month.ToString() + "/" + _Date.Day.ToString()
            Dim listTinhThanh As List(Of TinhThanh) = Nothing
            listTinhThanh = TinhThanhServer.GetListTinhThanhPhoBien()
            divListTinhThanh.InnerHtml = ""

            For i As Integer = 0 To listTinhThanh.Count - 1
                'Dim arr_str() As String = Split(WebConfigServer.GetValueWebConfigByKey("main_hotel_footer").ToUpper, listTinhThanh(i).NAME.ToUpper())
                ' Dim arr_str() As String = Split(Util.GetConfigKey("main_hotel_footer").ToUpper(), listTinhThanh(i).NAME.ToUpper())
                'If arr_str.Length > 1 Then
                divListTinhThanh.InnerHtml += String.Format("<div class='RightWrapCity'  ><a id_city='{0}' text='{1}' class='ui-link' title='Khách sạn {1}' href='#main-page' onclick='SelectCity(this);'>Khách sạn {1}</a></div>", listTinhThanh(i).ID, listTinhThanh(i).NAME)
                ' End If
                '' divListTinhThanhSearch.InnerHtml += String.Format("<li><a id_city='{0}' text='{1}' class='ui-link' title='Khách sạn {1}' href='#main-page' onclick='SelectCity(this);'>Khách sạn {1}</a></li>", listTinhThanh(i).ID, listTinhThanh(i).NAME.ToUpper())

            Next
            divListTinhThanhSearch.InnerHtml = ""
            Dim listTinhThanhSearch As List(Of TinhThanh) = TinhThanhServer.GetListTinhThanh()
            For j As Integer = 0 To listTinhThanhSearch.Count - 1
                divListTinhThanhSearch.InnerHtml += String.Format("<li><a id_city='{0}' text='{1}' class='ui-link' title='Khách sạn {1}' href='#main-page' onclick='SelectCity(this);'>Khách sạn {1}</a></li>", listTinhThanhSearch(j).ID, listTinhThanhSearch(j).NAME)
            Next
        End If
    End Sub

    Protected Sub lnkSearchTinhThanh_Click(sender As Object, e As EventArgs) Handles lnkSearchTinhThanh.Click
        Try
            Session("NameCity") = hdNameCity.Value
            If hdIDTinhThanhSelected.Value = "" Then
                Return
            End If
            Dim urL As String = String.Format("{5}/tim-khach-san.html?ArrivalDate={0}&DepartureDate={1}&CityID={2}&Guests={3}&Rooms={4}", ArrivalDate.Value, DepartureDate.Value, hdIDTinhThanhSelected.Value, Guests.Value, Rooms.Value, Util.GetConfigKey("RootURl"))
            Response.Redirect(urL)
        Catch ex As Exception
            ''Throw ex
        End Try
    End Sub

  
End Class
